﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GIMS.BLL;
using KPIS.GERP.GIMS.IBLL;
using KPIS.GERP.GIMS.MODEL;
using System.Data;
using System.IO;

namespace KPIS.GERP.GIMS.APP.APP_UI.Form
{
    public partial class ICM_Item_Request : System.Web.UI.Page
    {
        IBLLTree bllTree = new TreeBLL();
        IBLLSysYearType bllYearType = new SysYearTypeBLL();
        IBLLMasterPurchaseType bllPurchaseType = new MasterPurchaseTypeBLL();
        IBLLSysRecordStatus bllStatus = new SysRecordStatusBLL();
        IBLLSysProgress bllProgress = new SysProgressBLL();
        IBLLPrePurchaseRequest bllPPR = new PrePurchaseRequestBLL();
        SysControlBLL bllSysCon = new SysControlBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDefault();
                LoadYearType();
                LoadInvType();
                LoadRecordStatus();
                LoadJobSiteTree();
                LoadProgress();
                LoadDataGrid();
            }
        }

        protected void LoadDefault()
        {
            SysControlInfo infoDefault = bllSysCon.GetDefaultData();
            if (infoDefault.YearType != null)
            {
                cbYearType.SelectedValue = infoDefault.YearType.ToString();
                Session["yearSeq"] = cbYearType.SelectedValue;
                Session["yearSeq_Urgent"] = cbYearType.SelectedValue;
                
            }
            if (infoDefault.Year != null)
            {
                txtYear.Text = infoDefault.Year.ToString();
                Session["year"] = txtYear.Text;
                Session["year_Urgent"] = txtYear.Text;
            }
        }

        protected void LoadDataGrid()
        {
           

            DataTable dt;
            RequestBLL obj = new RequestBLL();
            dt = obj.Select();
            Grid.DataSource = dt;
            Grid.DataBind();  


        }


        protected void LoadYearType()
        {
            IList<SysYearTypeInfo> infoList = bllYearType.GetSysYearType();
            cbYearType.DataSource = infoList;
            cbYearType.DataBind();
        }


        protected void LoadInvType()
        {
            RequestBLL obj = new RequestBLL(); 
            DataTable dt;
            dt = obj.SelectInvType(); 
            cbMMType.DataSource = dt;
            cbMMType.DataBind();  

        }


        protected void LoadRecordStatus()
        {
            IList<SysRecordStatusInfo> infoList = bllStatus.GetSysRecordStatusTransaction();
            cbStatus.DataSource = infoList;
            cbStatus.DataBind();
        }

        public void LoadJobSiteTree()
        {
            IList<TreeInfo> info = bllTree.GetJobSiteTree();
            RadTreeView tree = (RadTreeView)cbJobSite.Items[0].FindControl("TreeViewJobSite");

            tree.DataSource = info;
            tree.DataBind();
        }

        protected void LoadProgress()
        {
            IList<SysProgressInfo> infoList = bllProgress.GetSysProgress();
            cbProgress.DataSource = infoList;
            cbProgress.DataBind();
        }

        protected void ShowGrid_Click(object sender, EventArgs e)
        {

        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            int[] data_value = new int[Grid.MasterTableView.GetSelectedItems().Length];
            int item = 0;
            foreach (GridDataItem data in Grid.MasterTableView.GetSelectedItems())
            {
                data_value[item] = Convert.ToInt32(data.Cells[2].Text);
                item++;
            }


            RequestBLL obj = new RequestBLL();

            for (int i = 0; i < data_value.Length; i++)
            {
            int seq;
                seq = data_value[i];

                obj.Delete(seq, Int32.Parse(Session["EmpSeq"].ToString())); 
            }
           LoadDataGrid();

            return;
        }



        protected void btnShow_Click(object sender, EventArgs e)
        {
            //if (RadTabStrip1.SelectedTab.Value == "Normal")
            //{
            //    LoadDataGrid();
            //    Session["yearSeq"] = cbYearType.SelectedValue;
            //    Session["year"] = txtYear.Text;
            //}
          
        }

        protected void RadManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
        {
            if (e.Argument == "CloseWindow")
            {
                LoadDataGrid();
            }
          
        }

        protected void Grid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            LoadDataGrid();
        }

   



        protected void OnAjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            RadAjaxPanel1.Controls.Add(Page.LoadControl("../UserControl/Personal_Data.ascx"));
        }

      



        protected void btnAddNew_Click(object sender, EventArgs e)
        {







        }
    }
}
